from gglib.model import Model


class _UserManager:
    def __init__(self):
        self._users = dict()

    def make_user(self, **kwargs):
        user = User(**kwargs)
        self._users[user.get_pk()] = user
        return user

    def __getitem__(self, item):
        return self._users[item]

    def __setitem__(self, key, value):
        assert isinstance(value, User)
        self._users[key] = value


class User(Model):
    manager = _UserManager()

    def __init__(self, username, **kwargs):
        self.username = username
        super().__init__(**kwargs)

    def get_pk(self):
        return self.username
